﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using Entity;
using BLL.Access;
using BLL;
using System.Data;

namespace Web.Controls.LAIHAN
{
    public partial class UCLHGaiHuTopInfo : System.Web.UI.UserControl, IUCLHOperate
    {
        #region 属性
        public string LaiHanID
        {
            get { return HiddenFieldList.Contains("LaiHanID") ? HiddenFieldList.Get("LaiHanID").ToString() : ""; }
            set { HiddenFieldList.Set("LaiHanID", value); }
        }
        public eLaiHanLCBH LaiHanLCBH
        {
            get;
            set;
        }
        #endregion

        #region 变量
       
        /// <summary>
        /// 日志信息BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();
        /// <summary>
        /// 用户信息主表
        /// </summary>
        YS_YG_YONGHUXXBLL BllYongHu = new YS_YG_YONGHUXXBLL();
        /// <summary>
        /// 存储过程访问类
        /// </summary>
        SpHelper _spHelper = new SpHelper();
        /// <summary>
        /// 来函用户调整信息BLL
        /// </summary>
        YS_LH_YONGHUTZProcess BllLaiHanYHTZ = new YS_LH_YONGHUTZProcess();
        /// <summary>
        /// 来函信息BLL
        /// </summary>
        YS_LH_LAIHANXXProcess BllLaiHanXX = new YS_LH_LAIHANXXProcess();

        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
                LoadLaiHanXXByID();
            }
        }
        /// <summary>
        /// 获得公司信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void dGongSiH_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
        {
            if (this.dJuHao.Value == null)
            {
                this.dGongSiH.Items.Clear();
            }
            else
            {
                PageTools.LoadComboxGongSi(this.dGongSiH, this.dJuHao.Value.ToString(), null);
            }
        }
        protected void BtnClear_Click(object sender, EventArgs e)
        {
            ClearInfo();
            SetControlStatus(false);
        }
        /// <summary>
        /// 用户号搜索
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            LoadYongHuXX();
            txtYongHuH1.Focus();
        }
        /// <summary>
        /// callback控件事件
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            if (e.Parameter == "yonghuh")
            {
                e.Result = e.Parameter + "|" + LoadYongHuXX();
            }
            else if (e.Parameter == "hetongh")
            {
                //获取合同号
                string hetongh = BusinessTool.GetHeTongH(this.txtYongHuH1.Text);
                e.Result = e.Parameter + "|0|" + hetongh;
            }
        }

        #endregion

        #region 方法
        public void InitControl()
        {
            SetControlStatus(false);
            //根据操作人加载管理部门(站点)
            DataTable dtZhanDian = BusinessTool.GetTextAndValue("View_AS_UserInfo", "ZHANDIANMC", "ZHANDIANBH", "-", string.Format("USERID={0}", LoginInfo.CurrentUser.UserID)).Tables[0];

            string zhendianBH = dtZhanDian.Rows[0]["VALUE"].ToString();


            //加载行政区

            DataTable XingZhengQ = BusinessTool.GetTextAndValue(
                    "YS_JX_XINGZHENGQ", "S_MINGCHENG", "S_BIANHAO", null, null
                ).Tables[0];

            PageTools.BindComboBox(
                this.dXingZhengQ, XingZhengQ
            );


            this.dXingZhengQ.SelectedIndex = 0;

            //this.dJuHao.ReadOnly = false;
            DataTable JuXinX = BusinessTool.GetTextAndValue(
                    "YS_JX_JUXINX", "S_MINGCHENG", "S_BIANHAO", null, "I_LEIXING=0 and (S_ZHANDIANBH='" + zhendianBH + "' or '00'='" + zhendianBH + "')"
                ).Tables[0];
            PageTools.BindComboBox(
                this.dJuHao, JuXinX
            );

            if (this.dJuHao.Items.Count > 0)
            {
                this.dJuHao.SelectedIndex = 0;

            }
            if (zhendianBH != "51" && zhendianBH != "00")
            {
                this.dJuHao.ReadOnly = true;

            }

            //加载业务员
            DataTable YeWuY = BusinessTool.GetTextAndValue(
                    "View_AS_UserInfo", "USERNAME", "USERID", null, string.Format("(ZHANDIANBH='{0}' or '00'='{0}') and ROLENAME like '%业务员%'", zhendianBH)
                ).Tables[0];
            PageTools.BindComboBox(
                this.dYeWuY, YeWuY
            );

            if (this.dYeWuY.Items.Count != 0)
            {
                this.dYeWuY.SelectedIndex = 0;

            }
            //加载用水性质
            DataTable YongShuiXZ = BusinessTool.GetTextAndValue(
                 "YS_JX_YONGSHUIXZ", "S_MINGCHENG", "S_BIANMA", "-", string.Format("I_TYPE={0}", zhendianBH.Contains("51") ? 1 : 0)
                 ).Tables[0];
            PageTools.BindComboBox(
                 this.dYongShuiXZ, YongShuiXZ
             );

            if (this.dYongShuiXZ.Items.Count != 0)
            {
                this.dYongShuiXZ.SelectedIndex = 0;

                LoadGongSiByJu();

            }
            //加载考核复用

            WordsManager manger = new WordsManager();
            DataTable FuYongKH = manger.Instance.FindWordsDataTableWithMiddleAffixByBelongID(WordsStruct.BelongID.考核复用, "-");
            PageTools.BindComboBox(this.dKaoHeFY, FuYongKH);

            if (this.dKaoHeFY.Items.Count != 0)
            {
                this.dKaoHeFY.SelectedIndex = 0;

            }
            //加载行业类型
            DataTable HangYeLB = BusinessTool.GetTextAndValue(
                 "YS_JX_HANGYELX", "S_SHESHUIDXFLMC", "S_SHESHUIDXFLDM", null, null
                 ).Tables[0];
            PageTools.BindComboBox(
                 this.dHangYeLB, HangYeLB
             );

            if (this.dHangYeLB.Items.Count != 0)
            {
                this.dHangYeLB.SelectedIndex = 0;

            }

        }
        /// <summary>
        /// 修改根据id加载来函信息
        /// </summary>
        private void LoadLaiHanXXByID()
        {
            if (Request["id"] != null&&(LaiHanID==""||LaiHanID=="0"))
            {
                LaiHanID = Request["id"];
            }
            if (LaiHanID != "" && LaiHanID != "0")
            {
                YS_LH_LAIHANXX laihan = BllLaiHanXX.SelectYS_LH_LAIHANXX(Convert.ToDecimal(Request["id"]));
                if (laihan != null)
                {
                    txtYongHuH.Text = laihan.S_YONGHUBH;
                    PageTools.SetDisabled(txtYongHuH, true);
                    txtLaiHanBH.Text = laihan.S_LAIHANBH;
                    txtLaiHanBH.BackColor = System.Drawing.Color.Transparent;
                    LoadInfo(laihan);
                    IUCLHOperate uc = this.Parent.FindControl("UCLHSJBTNS") as UCLHSJBTNS;
                    if (uc != null)
                    {
                        uc.LoadInfo(laihan);
                    }
                    uc = this.Parent.FindControl("UCLHBtnBottom") as UCLHBtnBottom;
                    if (uc != null)
                    {
                        uc.LoadInfo(laihan);
                    }
                }
                else
                {

                    PageTools.AlertMsg(this, "来函信息不存在", "window.close();");
                }
            }
            else
            {
                UCLHSJBTNS uc = this.Parent.FindControl("UCLHSJBTNS") as UCLHSJBTNS;
                if (uc != null)
                {
                    uc.LoadInfo(new YS_LH_LAIHANXX());
                }
                //PageTools.AlertMsg(this, "参数错误", "window.close();");
            }
        }
        /// <summary>
        /// 加载公司信息
        /// </summary>
        private void LoadGongSiByJu()
        {
            string juhao = "";
            if (dJuHao.Value==null) {
                return;
            }
            juhao = dJuHao.Value == null ? "" : dJuHao.Value.ToString();

            DataTable table = BusinessTool.GetTextAndValue(
                       "YS_JX_GONGSIXX", "S_MINGCHENG", "S_BIANHAO", null, string.Format("S_JUBIANH='{0}' and I_LEIXING=0", juhao)
                   ).Tables[0];

            if (table.Rows.Count > 0)
            {

                PageTools.BindComboBox(this.dGongSiH, table);
                this.dGongSiH.SelectedIndex = 0;

            }
            else
            {
                this.dGongSiH.Items.Clear();

            }

        }
        /// <summary>
        /// 根据用户号查询用户信息
        /// </summary>
        /// <returns></returns>
        private string LoadYongHuXX()
        {
            string YongHuH = txtYongHuH.Text;
            string msg="";
            if (LaiHanLCTools.HasRelationExists(10, "", txtYongHuH.Text, "", "", out msg))
            {
                return "-1|"+msg;
            }


            string wherecase = " S_YONGHUH='{0}' and i_jlzt=0 and i_leixing=0 and (S_ZHANDIANBH='{1}' or '00'='{1}') ";
            wherecase = string.Format(wherecase, YongHuH, BusinessTool.ZHANDIANBH());
            DataTable YongHuTable = BllYongHu.SelectYS_YG_YONGHUXXesDynamic(wherecase, "", null);
            if (YongHuTable != null && YongHuTable.Rows.Count > 0)
            {
                HiddenFieldList.Set("YongHuH", YongHuH);

                SetValueYongHuXX(YongHuTable);
                return "1|用户信息查询成功";
            }
            else
            {
                return "-1|查询不到该用户信息";
            }

        }
        /// <summary>
        /// 根据用户号查询用户信息
        /// </summary>
        /// <param name="dt"></param>
        private void SetValueYongHuXX(DataTable dt)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                string HeTongH = _spHelper.P_YS_GETHETONGH(dr["S_YONGHUH"].ToString()).Tables[0].Rows[0][0].ToString();
                HiddenFieldList.Set("ZHANDIAN", dr["S_ZHANDIANBH"]);
                HiddenFieldList.Set("GUANLIK", dr["S_GUANLIKBH"]);

                txtYongHuM1.Text = dr["S_YONGHUM"].ToString();
                txtDiZhi1.Text = dr["S_DIZHI"].ToString();
                dXingZhengQ.Value = dr["S_XINGZHENGQBH"].ToString();
                dJuHao.Value = dr["S_JUBIANH"].ToString();
                LoadGongSiByJu();

                dGongSiH.Value = dr["S_GONGSIBH"].ToString();

                dYeWuY.Value = dr["S_YEWUY"].ToString();
                txtLianXiR.Text = dr["S_LIANXIR"].ToString();
                txtLianXiDH.Text = dr["S_LIANXIDH"].ToString();
                txtLianXiBM1.Value = dr["S_LIANXIBM"].ToString();
                txtYouBian.Text = dr["S_YOUBIAN"].ToString();

                dYongShuiXZ.Value = dr["S_YONGSHUIXZ"].ToString();
                dHangYeLB.Value = dr["S_SHESHUIDXDM"].ToString();
                txtYongShuiJ.Text = dr["N_YSJ"].ToString();
                dKaoHeFY.Value = dr["I_KAOHEFY"].ToString();
                txtKaiHuHM.Text = dr["S_KAIHUHM"].ToString();

                txtKaiHuYH.Text = dr["S_KAIHUYH"].ToString();
                txtKaiHuZH.Text = dr["S_YINHANGZH"].ToString();
                if (dr["I_SHOUFEIFS"].ToString() == "1")
                {
                    cTuoShou.Checked = true;
                }
                this.txtHeTongH.Text = HeTongH;
                SetControlStatus(true);
            }
        }
        /// <summary>
        /// 设置控件状态
        /// </summary>
        /// <param name="status"></param>
        public void SetControlStatus( bool status)
        {
            ControlCollection controls = this.Controls;
            
            foreach (Control c in controls)
            {
                if (c is DevExpress.Web.ASPxTextBox)
                {
                    DevExpress.Web.ASPxTextBox txt = c as DevExpress.Web.ASPxTextBox;
                    
                    if (txt.ClientID != txtYongHuH.ClientID&&txt.ClientID!=txtLaiHanBH.ClientID&&txtHeTongH.ClientID!=txt.ClientID)
                    {
                        //PageTools.SetDisabled(txt, !status);
                        txt.ClientEnabled = status;
                    }
                }
                else
                    if (c is DevExpress.Web.ASPxComboBox)
                    {
                        DevExpress.Web.ASPxComboBox com = c as DevExpress.Web.ASPxComboBox;
                        //com.ReadOnly = !status;
                        com.ClientEnabled = status;

                    }
                    else
                        if (c is DevExpress.Web.ASPxCheckBox)
                        {
                            DevExpress.Web.ASPxCheckBox check = c as DevExpress.Web.ASPxCheckBox;
                            //check.ReadOnly = !status;                          
                            check.ClientEnabled = status;
                        }

            }
            //txtYongHuH.Focus();

            
        }
        /// <summary>
        /// 提交验证
        /// </summary>
        /// <returns></returns>
        public ValidateRS Validate()
        {
            ValidateRS rs = new ValidateRS();
            rs.IsSuccess = false;
            string where = " S_YONGHUH='{0}' and i_JLZT=0 ";

            string where1 = string.Format(where, txtYongHuH1.Text.Trim());
            string XiuGaiWhere = "";
            if (LaiHanID!=""&&LaiHanID!="0")
            {
                XiuGaiWhere = " and S_YUANYONGHUH<>'{0}'";
                XiuGaiWhere = string.Format(XiuGaiWhere, HiddenFieldList.Get("YongHuH").ToString());
            }
           

            DataTable dt1 = BllYongHu.SelectYS_YG_YONGHUXXesDynamic(where1, "", null);
            DataTable dt11 = BllLaiHanYHTZ.SelectYS_LH_YONGHUTZsDynamic(where1+XiuGaiWhere, "", null);
            if ((dt1.Rows.Count > 0 || dt11.Rows.Count > 0))
            {
                rs.Msg = "新用户号已存在";
                txtYongHuH1.Focus();
                return rs;
            }

            if (txtYongHuH.Text.Trim().Length == 0)
            {
                rs.Msg = "用户号不能为空";
                txtYongHuH.Focus(); return rs;
            }

            if (txtYongHuH1.Text.Trim().Length == 0)
            {
                rs.Msg = "新用户号不能为空";
                txtYongHuH1.Focus(); return rs;
            }
            if (txtYongHuH1.Text.Trim().Substring(0, 2) != txtYongHuH.Text.Trim().Substring(0, 2))
            {
                txtYongHuH1.Focus();
                
                rs.Msg = "新用户号格式错误（前两位为管理块号）";
                return rs;
            }
            if (txtYongHuH1.Text.Trim().Length != 7)
            {
                txtYongHuH1.Focus();
                
                rs.Msg = "新用户号应该为7位";
                return rs;
            }
            for (int i = 0; i < txtYongHuH1.Text.Trim().Length; i++)
            {
                byte b = Convert.ToByte(txtYongHuH1.Text.Trim()[i]);
                if (b < 48 || b > 57)
                {
                    rs.Msg = "新用户号只允许为数字";
                    txtYongHuH1.Focus(); return rs;
                }
            }
            if (txtYongHuM1.Text.Trim().Length == 0)
            {
                rs.Msg = "用户名不能为空";
                txtYongHuM1.Focus(); return rs;
            }
            if (txtDiZhi1.Text.Trim().Length == 0)
            {
                rs.Msg = "地址不能为空";
                txtDiZhi1.Focus(); return rs;
            }
            if (dXingZhengQ.Value == null || dXingZhengQ.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择行政区";
                dXingZhengQ.Focus(); return rs;
            }
            //if (dJuHao.Value == null || dJuHao.Value.ToString().Trim().Length == 0)
            //{
            //    rs.Msg = "请选择局号";
            //    dJuHao.Focus(); return rs;
            //}

            if (dYeWuY.Value == null || dYeWuY.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择业务员";
                dYeWuY.Focus(); return rs;
            }
            if (txtLianXiR.Text.Trim().Length == 0)
            {
                rs.Msg = "联系人不能为空";
                txtLianXiR.Focus(); return rs;
            }
            if (txtLianXiDH.Text.Trim().Length == 0)
            {
                rs.Msg = "联系电话不能为空";
                txtLianXiDH.Focus(); return rs;
            }
            if (txtLianXiBM1.Text.Trim().Length == 0)
            {
                rs.Msg = "联系部门不能为空";
                txtLianXiBM1.Focus(); return rs;
            }
            if (txtYouBian.Text.Trim().Length == 0)
            {
                rs.Msg = "邮编不能为空";
                txtYouBian.Focus(); return rs;
            }
            if (dYongShuiXZ.Value == null || dYongShuiXZ.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择用水性质";
                dYongShuiXZ.Focus(); return rs;
            }
            if (dHangYeLB.Value == null || dHangYeLB.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择行业类别";
                dHangYeLB.Focus(); return rs;
            }
            if (txtYongShuiJ.Text.Trim().Length == 0 || Convert.ToDouble(txtYongShuiJ.Text) < 0)
            {
                rs.Msg = "用水价不能为空";
                txtYongShuiJ.Focus(); return rs;
            }
            if (dKaoHeFY.Value == null || dKaoHeFY.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择考核复用";
                dKaoHeFY.Focus(); return rs;
            }
            if (cTuoShou.Checked)
            {
                if (txtKaiHuHM.Text.Trim().Length == 0)
                {
                    rs.Msg = "开户户名不能为空";
                    txtKaiHuHM.Focus(); return rs;
                }
                if (txtKaiHuYH.Text.Trim().Length == 0)
                {
                    rs.Msg = "开户银行不能为空";
                    txtKaiHuYH.Focus(); return rs;
                }
                if (txtKaiHuZH.Text.Trim().Length == 0)
                {
                    rs.Msg = "开户账号不能为空";
                    txtKaiHuZH.Focus(); return rs;
                }
                if (txtHeTongH.Text.Trim().Length == 0)
                {
                    rs.Msg = "合同号不能为空";
                    txtHeTongH.Focus(); return rs;
                }
            }
            rs.IsSuccess = true;
            return rs;
        }

        /// <summary>
        /// 获取来函信息
        /// </summary>
        /// <param name="isAdd"></param>
        /// <param name="liuchengzt"></param>
        /// <returns></returns>
        public YS_LH_LAIHANXX GetLaiHanXX(bool isAdd, int liuchengzt)
        {
            YS_LH_LAIHANXX laihan = new YS_LH_LAIHANXX();

            if (LaiHanID!=""&&LaiHanID!="0")
            {
                laihan = BllLaiHanXX.SelectYS_LH_LAIHANXX(Convert.ToDecimal(LaiHanID));
            }
            else
            {
                string laihanbh = "";
                string xukebh = "";
                string zd, glk, ywy;
                PageTools.GetLHDJZDGLKYWY(txtYongHuH.Text, out zd, out glk, out ywy);
                laihan.S_ZHANDIANBH = zd;
                laihan.S_GUANLIKBH = glk;
                laihan.I_YWY = int.Parse(ywy);
                laihan.S_YWY = BusinessTool.GetYWYName(ywy);
                //laihan.S_YHYWY = ywy;
                DataSet numset = new SpHelper().P_YS_LH_XUKEBH(glk, 10, 0,(BusinessTool.GetWaterYM() / 100).ToString(), out xukebh, out laihanbh);
                //DataSet numset = new SpHelper().P_YS_LH_XUKEBH(HiddenFieldList.Get("GUANLIK").ToString(), 10, 0, (BusinessTool.GetWaterYM() / 100).ToString(), out xukebh, out laihanbh);
                laihan.I_XT = BusinessTool.WType;
                int waterYM = BusinessTool.GetWaterYM();
                laihan.ID = 0;
                laihan.I_Y = Convert.ToInt32(waterYM.ToString().Substring(0,4));
                laihan.I_M = waterYM%100;
                laihan.D_CAOZUOSJ = DateTime.Now;
                laihan.D_LAIHANRQ = DateTime.Now;
                laihan.D_SHURURQ = DateTime.Now;
                laihan.I_AUTOTYPE = 0;
                laihan.I_JLZT = 0;
                laihan.I_LAIHANLX = 10;
                laihan.I_SHURUR = LoginInfo.CurrentUser.UserID;
                laihan.I_LIUCHENGZT = 0;
                
                //laihan.S_GUANLIKBH = HiddenFieldList.Get("GUANLIK").ToString();
                laihan.S_LAIHANBH =laihanbh;
                laihan.S_TONGYIBM = "";
                laihan.S_XUKEBH = xukebh;
                laihan.S_YONGHUBH = txtYongHuH.Text;
                DataRowCollection drcT=new YS_YG_YONGHUXXProcess().SelectYS_YG_YONGHUXXesDynamic("I_JLZT=0 AND I_LEIXING=1 AND S_YONGHUH='"+this.txtYongHuH.Text+"'",null).Rows;
                laihan.S_YONGHUM=Convert.ToString(drcT[0]["S_YONGHUM"]);
                //laihan.S_ZHANDIANBH = HiddenFieldList.Get("ZHANDIAN").ToString();
                
            }
            laihan.I_LIUCHENGBH = liuchengzt;
            laihan.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            laihan.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
            return laihan;
        }

        /// <summary>
        /// 清空数据
        /// </summary>
        public void ClearInfo()
        {
            ControlCollection controls = this.Controls;

            foreach (Control c in controls)
            {
                if (c is DevExpress.Web.ASPxTextBox)
                {
                    DevExpress.Web.ASPxTextBox txt = c as DevExpress.Web.ASPxTextBox;

                    if (txt.ClientID != txtYongHuH.ClientID)
                    {
                        txt.Text = "";
                    }
                }
                else
                    if (c is DevExpress.Web.ASPxComboBox)
                    {
                        DevExpress.Web.ASPxComboBox com = c as DevExpress.Web.ASPxComboBox;
                        com.SelectedIndex = -1;

                    }
                    else
                        if (c is DevExpress.Web.ASPxCheckBox)
                        {
                            DevExpress.Web.ASPxCheckBox check = c as DevExpress.Web.ASPxCheckBox;
                            check.Checked = false;

                        }

            }
            txtYongHuH.Focus();
        }

        /// <summary>
        /// 插入用户调整信息
        /// </summary>
        /// <param name="type"></param>
        /// <param name="laihanxx"></param>
        public void InsertYongHuXX(YS_LH_LAIHANXX laihanxx)
        {
            OperateState operateState;
            string laihanbh = laihanxx.S_LAIHANBH;

            YS_LH_YONGHUTZ yhxx = new YS_LH_YONGHUTZ();
            yhxx.D_CAOZUOSJ = DateTime.Now;
            yhxx.I_JLZT = 0;

            yhxx.I_LEIXING = 0;
            yhxx.I_YONGHUZT = 0;
            yhxx.ID = 0;
            yhxx.I_YUANYONGH = 1;
            yhxx.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            yhxx.S_YUANYONGHUH = HiddenFieldList.Get("YongHuH").ToString();
            yhxx.S_GUANLIKBH = HiddenFieldList.Get("GUANLIK").ToString();
            yhxx.S_ZHANDIANBH = HiddenFieldList.Get("ZHANDIAN").ToString();
            yhxx.S_LAIHANBH = laihanbh;

            yhxx.S_YONGHUH = txtYongHuH1.Text;
            yhxx.S_YONGHUM = txtYongHuM1.Text;
            yhxx.S_DIZHI = txtDiZhi1.Text;
            yhxx.S_XINGZHENGQBH = dXingZhengQ.Value.ToString();
            yhxx.S_JUBIANH = dJuHao.Value==null?"":dJuHao.Value.ToString();
            if (dGongSiH.Value != null)
            {
                yhxx.S_GONGSIBH = dGongSiH.Value.ToString();
            }
            yhxx.S_YEWUY = dYeWuY.Value.ToString();
            yhxx.S_LIANXIR = txtLianXiR.Text;
            yhxx.S_LIANXIDH = txtLianXiDH.Text;
            yhxx.S_LIANXIBM = txtLianXiBM1.Text;

            yhxx.S_YOUBIAN = txtYouBian.Text;
            yhxx.S_YONGSHUIXZ = dYongShuiXZ.Value.ToString();
            yhxx.S_SHESHUIDXDM = dHangYeLB.Text;
            yhxx.N_YSJ = Convert.ToDouble(txtYongShuiJ.Text);
            yhxx.I_KAOHEFY = Convert.ToInt32(dKaoHeFY.Value);

            yhxx.S_KAIHUHM = txtKaiHuHM.Text;
            yhxx.S_KAIHUYH = txtKaiHuYH.Text;
            yhxx.S_YINHANGZH = txtKaiHuZH.Text;
            yhxx.I_SHOUFEIFS = (cTuoShou.Checked == true ? 1 : 0);
            yhxx.S_BEIYONG5 = txtHeTongH.Text; 

            string where = " S_LAIHANBH='{0}' and S_YUANYONGHUH='{1}' and i_jlzt=0  ";
            where = string.Format(where, laihanbh, laihanxx.S_YONGHUBH);
            DataTable dt = BllLaiHanYHTZ.SelectYS_LH_YONGHUTZsDynamic(where, null, null);
            if (dt != null && dt.Rows.Count > 0)
            {
                yhxx.ID = Convert.ToInt32(dt.Rows[0]["ID"]);
            }
            if (yhxx.ID == 0)
            {
                operateState = OperateState.Add;
            }
            else
            {
                operateState = OperateState.Modify;
            }
            _SYS_LOGBLL.Log<YS_LH_YONGHUTZ>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "来函管理-改户流程", operateState, yhxx, null);
            if (BllLaiHanYHTZ.InsertOrUpdate(yhxx))
            {
                

            }
        }

        /// <summary>
        /// 修改根据来函信息绑定用户信息
        /// </summary>
        /// <param name="laihanxx"></param>
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            txtYongHuH.Text = laihanxx.S_YONGHUBH;
            txtYongHuH.ClientEnabled = false;
            //PageTools.SetDisabled(txtYongHuH, true);
            txtLaiHanBH.Text = laihanxx.S_LAIHANBH;
            txtLaiHanBH.BackColor = System.Drawing.Color.Transparent;
            LaiHanID = laihanxx.ID.ToString();

            string where = " S_LAIHANBH='{0}' and S_YUANYONGHUH='{1}'  and i_jlzt=0 ";
            where = string.Format(where,laihanxx.S_LAIHANBH,laihanxx.S_YONGHUBH);
            DataTable dt = BllLaiHanYHTZ.SelectYS_LH_YONGHUTZsDynamic(where,"",null);
            if (dt != null && dt.Rows.Count > 0)
            {

                DataRow dr = dt.Rows[0];

                HiddenFieldList.Set("YongHuH", laihanxx.S_YONGHUBH);
                HiddenFieldList.Set("ZHANDIAN", dr["S_ZHANDIANBH"]);
                HiddenFieldList.Set("GUANLIK", dr["S_GUANLIKBH"]);
                string HeTongH = _spHelper.P_YS_GETHETONGH(dr["S_YONGHUH"].ToString()).Tables[0].Rows[0][0].ToString();
                txtYongHuH1.Text = dr["S_YONGHUH"].ToString();

                txtYongHuM1.Text = dr["S_YONGHUM"].ToString();
                txtDiZhi1.Text = dr["S_DIZHI"].ToString();
                dXingZhengQ.Value = dr["S_XINGZHENGQBH"].ToString();
                dJuHao.Value = dr["S_JUBIANH"].ToString();
                LoadGongSiByJu();

                dGongSiH.Value = dr["S_GONGSIBH"].ToString();

                dYeWuY.Value = dr["S_YEWUY"].ToString();
                txtLianXiR.Text = dr["S_LIANXIR"].ToString();
                txtLianXiDH.Text = dr["S_LIANXIDH"].ToString();
                txtLianXiBM1.Value = dr["S_LIANXIBM"].ToString();
                txtYouBian.Text = dr["S_YOUBIAN"].ToString();

                dYongShuiXZ.Value = dr["S_YONGSHUIXZ"].ToString();
                dHangYeLB.Value = dr["S_SHESHUIDXDM"].ToString();
                txtYongShuiJ.Text = dr["N_YSJ"].ToString();
                dKaoHeFY.Value = dr["I_KAOHEFY"].ToString();
                txtKaiHuHM.Text = dr["S_KAIHUHM"].ToString();

                txtKaiHuYH.Text = dr["S_KAIHUYH"].ToString();
                txtKaiHuZH.Text = dr["S_YINHANGZH"].ToString();
                if (dr["I_SHOUFEIFS"].ToString() == "1")
                {
                    cTuoShou.Checked = true;
                }
                this.txtHeTongH.Text = HeTongH;

                SetControlStatus(true);
                if (LaiHanLCBH == eLaiHanLCBH.登记)
                {
                    SetControlStatus(false);
                    txtYongHuH.Enabled = false;
                   
                }
            }
        }
        #endregion
    }
}